Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: add opf-load-once capability on js and css resources #19825

Merged
merged 10 commits into from
Jan 13, 2025

Conversation

FollowTheFlo
Copy link
Contributor

No description provided.

@FollowTheFlo FollowTheFlo requested a review from a team as a code owner January 3, 2025 19:38
@github-actions github-actions bot marked this pull request as draft January 3, 2025 19:39
protected readonly CORS_DEFAULT_VALUE = 'anonymous';
protected readonly OPF_RESOURCE_LOAD_ONCE_ATTR_KEY = 'opf-load-once';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we use for consistency: OPF_RESOURCE_LOAD_ONCE_ATTRIBUTE_KEY?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also would be good in my opinion to prefix all custom html attributes with "data-".
https://www.w3schools.com/tags/att_data-.asp

Can we change attribute key to: data-opf-load-once?

Copy link
Contributor Author

@FollowTheFlo FollowTheFlo Jan 9, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need to add 'data-' prefix:
'opf-load-once' is never added as attribute key, it is just a variable that decides if we add 'data-opf-resource' attribute or not.
To sum-up, we receive it in attributes property from server but using it as a flag in this service.


protected embedStyles(embedOptions: {
attributes?: OpfKeyValueMap[];
attributes?: { [key: string]: string };
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it new type different than OpfKeyValueMap[]?

Copy link
Contributor Author

@FollowTheFlo FollowTheFlo Jan 9, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, it was set as 'any'.
OpfKeyValueMap is {key:string,value:string}, we receive the list in this format from resource object (resource.attributes).
We perform a conversion to [key: string]: string to make handling easier and have same type as attributes in ScriptLoader service

@@ -82,31 +103,21 @@ export class OpfResourceLoaderService {
*/
protected loadScript(resource: OpfDynamicScriptResource): Promise<void> {
return new Promise((resolve, reject) => {
const attributes: any = {
const attributes: { [key: string]: string } = {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we create type for it in a model if we cannot use: OpfKeyValueMap?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mentioned above, we need both:
OpfKeyValueMap is the original format (resource.attributes received from server)
{ [key: string]: string } is format needed for ScriptLoaderService
Thus a conversion is needed.

@FollowTheFlo FollowTheFlo marked this pull request as ready for review January 12, 2025 20:47
Copy link

cypress bot commented Jan 12, 2025

spartacus    Run #46637

Run Properties:  status check passed Passed #46637  •  git commit 381a9f9b09 ℹ️: Merge caab9fda3dcef0349f31641a43f068ca8c0c7735 into 2b9e915b7a0bf2fe0a1fec5565fd...
Project spartacus
Branch Review feature/CXSPA-8883_v2
Run status status check passed Passed #46637
Run duration 03m 50s
Commit git commit 381a9f9b09 ℹ️: Merge caab9fda3dcef0349f31641a43f068ca8c0c7735 into 2b9e915b7a0bf2fe0a1fec5565fd...
Committer Florent Letendre
View all properties for this run ↗︎

Test results
Tests that failed  Failures 0
Tests that were flaky  Flaky 3
Tests that did not run due to a developer annotating a test with .skip  Pending 2
Tests that did not run due to a failure in a mocha hook  Skipped 0
Tests that passed  Passing 125
View all changes introduced in this branch ↗︎

@Matejk00 Matejk00 self-requested a review January 13, 2025 13:53
Copy link
Contributor

@Matejk00 Matejk00 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@github-actions github-actions bot marked this pull request as draft January 13, 2025 14:38
@FollowTheFlo FollowTheFlo marked this pull request as ready for review January 13, 2025 14:39
@FollowTheFlo FollowTheFlo merged commit d19780b into develop Jan 13, 2025
28 checks passed
@FollowTheFlo FollowTheFlo deleted the feature/CXSPA-8883_v2 branch January 13, 2025 14:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants